<?php


namespace app\adminapi\controller\user;


use app\adminapi\BaseAdminController;
use app\adminapi\dao\user\UserDao;
use app\adminapi\lists\user\UserLists;
use app\adminapi\lists\user\UserTypeLists;
use app\adminapi\validate\user\UserValidate;

/**
 * @projectName src
 */
class User extends BaseAdminController
{
    public function add()
    {
        $params = (new UserValidate())->post([
            'user_name',
            'user_gender',
            'user_idno',
            'user_type',
            'user_phone',
        ])->goCheck('add');
        UserDao::add($params);
        return $this->success('添加成功', [], 200, 1);
    }

    public function edit()
    {
        $params = (new UserValidate())->post([
            'id',
            'user_name',
            'user_gender',
            'user_idno',
            'user_type',
            'user_phone',
        ])->goCheck('edit');
        $result = UserDao::edit($params);
        if (true === $result) {
            return $this->success('编辑成功', [], 200, 1);
        }
        return $this->fail(UserDao::getError());
    }

    public function delete()
    {
        $params = (new UserValidate())->post([
            'id'
        ])->goCheck('delete');
        UserDao::delete($params);
        return $this->success('删除成功', [], 200, 1);
    }

    public function detail()
    {
        $params = (new UserValidate())->get([
            'id'
        ])->goCheck('detail');
        $result = UserDao::detail($params);
        return $this->data($result);
    }

    public function all()
    {
        $result = UserDao::getAllData();
        return $this->data($result);
    }

    /**
     * 获取列表
     */
    public function lists()
    {
        return $this->dataLists(new UserLists());
    }

}